#include <stdio.h>
#include "main.h"

int delcontact(FILE* file, struct contact data[], int* p_index)
{
	int i, option;
	printf("Enter the contact (index) that you want to delete:\n");
	scanf("%d", &option);
	if (option < 0 || option > (*p_index)){
		printf("Invalid index.\n");
		return 1;
	} 
	else {
		for (i = 0; i < NAME_MAX; i++){
			data[option].name[i] = ' ';
		}
		data[option].age = 0;
		for (i = 0; i < TEL_MAX; i++){
			data[option].tel[i] = ' ';
		}

		(*p_index)--;
		printf("Contact deleted...\n");
		printf("You have %d contact(s).\n", (*p_index));
		return 0;
	}
}
